import com.mysql.jdbc.Connection;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-11-16
 * Time: 19:44
 * To BE A Better Person-2020-3-2
 */
public class JDBCmess {
    private static DataSource dataSource=null;
   private static DataSource getDataSource(){
       if(dataSource == null){
           dataSource=new MysqlDataSource();
           ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/messagewall?characterEncoding=utf8&useSSL=false");
           ((MysqlDataSource)dataSource).setUser("root");
           ((MysqlDataSource)dataSource).setPassword("lakers26");
       }
       return dataSource;
   }
   public static Connection getConnection() throws SQLException {
       return (Connection) getDataSource().getConnection();
   }
   public static void close(Connection connection, PreparedStatement statement, ResultSet resultSet) throws SQLException {
       if (connection != null){
           connection.close();
       }
       if(statement != null){
           statement.close();
       }
       if(resultSet != null){
           resultSet.close();
       }
   }
}
